﻿using PETimer;
using UnityEngine;

public class FrameTimerExample : MonoBehaviour {
    FrameTimer timer;

    private void Start() {
        timer = new FrameTimer(1);
    }

    int tid;
    private void Update() 
    {
        timer.UpdateTask();

        if(Input.GetKeyDown(KeyCode.A)) {
            Extension.Log("CurrentFrame:" + Time.frameCount);
            tid = timer.AddTask(
                1000,
                (int tid) => {
                    Extension.Log($"tid:{tid} work. frame:{ Time.frameCount}");
                },
                (int tid) => {
                    Extension.Log($"tid:{tid} cancel.");
                },
                5);
        }

        if(Input.GetKeyDown(KeyCode.Delete)) {
            timer.DeleteTask(tid);
        }
    }
}
